package cm.app.login.action;

import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.HandlesEvent;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.integration.spring.SpringBean;
import cm.app.login.form.LoginForm;
import cm.app.login.service.LoginService;
import cm.app.user.action.UserActionBean;
import cm.fw.base.CommonActionBean;

public class LoginActionBean
        extends CommonActionBean {

    /** ログインマネージャー */
    @SpringBean("loginService")
    private LoginService loginService;

    private LoginForm    form;

    /**
     * doLogin
     * 
     * <PRE>
     * ログイン認証
     * </PRE>
     * 
     * @return　フォワード
     */
    @HandlesEvent("login")
    public Resolution doLogin()
            throws Exception {

        // ログイン成功
        if (loginService.doLogin(form.getLoginId(), form.getPassword()) == 1) {
            return new RedirectResolution(UserActionBean.class, "load");
        }

        return new ForwardResolution("jsp/login/login.jsp");
    }
    
    public void setForm(LoginForm form) {
        this.form = (LoginForm)form;
    }
}
